<?php
namespace Pay\Service\Alipay;

use Pay\Service\Alipay\ActionAbstract;

class App extends ActionAbstract
{

    /*
     * 如果没有参数config默认取自有的配置
     */
    public function __construct($config = false)
    {
        parent::__construct($config);
    }

    /*
     * 进行H5支付
     * 一些必要参数$params如下:
     * $params['price']:价格
     * $params['subject']:标题
     * $params['orderNumber']:订单编号
     * $params['redirectUrl']:支付完成后显示的页面(可空)
     */
    public function doApp($params)
    {
        if (!$params['price'] || !$params['subject']) {
            return false;
        }

        if (!$params['orderNumber']) {
            return false;
        }
        
        $ret = include (__DIR__ . '/../../Alipay/request/AlipayTradeAppPayRequest.php');
        $subject = $params['subject'];
        $price = $params['price'];
        $orderNumber = $params['orderNumber'];
        $redirectUrl = $params['redirectUrl'] ? : '';
        $payCode = 'QUICK_MSECURITY_PAY';//非必须,商家和支付宝签约的产品码

        $request = new \AlipayTradeAppPayRequest();
        $bizcontent = "{\"body\":\"购买服务\","
            . "\"subject\": \".$subject.\","
            . "\"out_trade_no\": \"".$orderNumber."\","
            . "\"timeout_express\": \"30m\","
            . "\"total_amount\": \"".$price."\","
            . "\"product_code\":\"".$payCode."\""
            . "}";
        $request->setReturnUrl($redirectUrl);
        $request->setNotifyUrl($this->config['notifyUrl']);
        $request->setBizContent($bizcontent);
        $response = $this->aopclient->pageExecute($request);
        return $response ? : false;
    }
}
?>
